<!DOCTYPE html>
<html>
<head>
    <title>订单申请管理</title>
    <#include "/header.html">
    <style>
        .album-img {
            cursor: pointer;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div style="margin: 10px 0">
            <form class="layui-form layui-form-pane" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">订单号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="tradeNo" placeholder="搜索订单尾号" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-primary layui-border-blue" lay-submit lay-filter="form-search-btn"><i class="layui-icon layui-icon-search"></i>搜索</button>
                        <button class="layui-btn layui-btn-primary" lay-submit lay-filter="form-reset-btn"><i class="layui-icon layui-icon-refresh"></i>重置</button>
                    </div>
                </div>
            </form>
        </div>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
    </div>
</script>

<script type="text/html" id="currentTableMobileTpl">
    <div>{{d.mobile}}</div>
    <div>{{d.email}}</div>
</script>

<script type="text/html" id="currentTableImagesTpl">
    <div id="layer-photos-view{{d.id}}">
        {{# layui.each(d.images, function(i, src){ }}
        <img class="album-img" layer-pid="{{i}}" layer-src="{{src}}" src="{{src}}" alt="{{i}}" width="45">
        {{# }); }}
    </div>
</script>

<script type="text/html" id="currentTableStatusTpl">
    {{# if(d.status == 51){ }}
    <span class="layui-badge layui-bg-orange">已申诉</span>
    {{# } else if(d.status == 50){ }}
    <span class="layui-badge layui-bg-blue">已审核</span>
    {{# } else if(d.status == 20){ }}
    <span class="layui-badge layui-bg-black">已驳回</span>
    {{# } else { }}
    <span class="layui-badge layui-bg-grey">待审核</span>
    {{# } }}
</script>

<script type="text/html" id="currentTableBar">
<#if shiro.hasPermission("app:order:appeal:save")>
    {{# if(d.status == 0){ }}
    <a class="layui-btn layui-btn-primary layui-border-green layui-btn-xs" lay-event="more">操作 <i class="layui-icon layui-icon-down"></i></a>
    {{# } }}
    {{# if(d.status == 51){ }}
    <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="view">查看申诉</a>
    {{# } }}
</#if>
</script>

<script type="text/javascript">
    var formDataId = 0;
    layui.use(['dropdown', 'form', 'table'], function () {
        var $ = layui.jquery,
            dropdown = layui.dropdown,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: serverUrl('app/order/appeals'),
            toolbar: false,
            // defaultToolbar: ['filter'],
            cols: [[
                {field: 'orderTradeNo', title: '订单编号', width: 160},
                {field: 'userName', title: '用户名称', minWidth: 120},
                {field: 'mobile', title: '联系方式', minWidth: 180, templet: '#currentTableMobileTpl'},
                {field: 'storeName', title: '店铺名称', minWidth: 120},
                {field: 'reason', title: '投诉原因', minWidth: 120},
                {field: 'description', title: '说明', minWidth: 180},
                {field: 'images', title: '凭证图片', width: 180, templet: '#currentTableImagesTpl'},
                {field: 'status', title: '状态', width: 80, templet: '#currentTableStatusTpl'},
                {field: 'content', title: '审核说明', minWidth: 180},
                {title: '操作', width: 90, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 25, 50],
            limit: 10,
            page: true,
            done:function(res){
                $(res.data).each(function (i, d) {
                    layer.photos({
                        photos: '#layer-photos-view'+d.id
                        ,anim: 5 //0-6的选择，指定弹出图片动画类型，默认随机（请注意，3.0之前的版本用shift参数）
                    });
                });
            }
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var that = this;
            var data = obj.data;
            if (obj.event === 'view') {
                formDataId = data.id;
                layerOpen = layer.open({
                    title: '申诉信息',
                    type: 2,
                    shade: 0.5,
                    maxmin: true,
                    area: ['95%', '90%'],
                    content: serverUrl('app/order/appeal-info.html')
                });
            }
            else if(obj.event === 'more'){
                //更多下拉菜单
                dropdown.render({
                    elem: that
                    ,show: true //外部事件触发即显示
                    ,data: [{
                        title: '通过'
                        ,templet: '<span class="text-blue"><i class="layui-icon layui-icon-ok"></i>{{d.title}}</span>'
                        ,id: 'pass'
                    }, {
                        title: '驳回'
                        ,templet: '<span class="text-red"><i class="layui-icon layui-icon-close"></i>{{d.title}}</span>'
                        ,id: 'reject'
                    }]
                    ,click: function(res, othis){
                        //根据 id 做出不同操作
                        var title = res.id === 'pass' ? '确定通过吗？' : '确定驳回吗？';
                        var status = res.id === 'pass' ? 50 : 20;
                        openPrompt(title, '填写说明', function(value){
                            submitFormData('app/order/appeal-update', {id: data.id, status: status, content: value}, function(){table.reload('currentTableId')});
                        });
                    }
                });
            }
        });

        // 监听搜索操作
        initSearchForm('searchForm', 'currentTableId');

    });
</script>

</body>
</html>